//
//  CustomHeadFooterView.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/11/1.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "CustomHeadFooterView.h"
#import "HWGroupModel.h"

@interface CustomHeadFooterView()
@property(strong,nonatomic) UIImageView *icoIamgeView;
@property(strong,nonatomic) UILabel *nameNiChengLabel;
@property(strong,nonatomic) UILabel *liaboshuliaLabel;
@property(strong,nonatomic) UILabel *libao1Label;
@property(strong,nonatomic) UILabel *libao2Label;
@property(strong,nonatomic) UILabel *libao3Label;
@property(strong,nonatomic) UIButton *zhangkaiBut;



@end

@implementation CustomHeadFooterView

+ (instancetype)headFooterViewWithTableview:(UITableView *)tableview {
    
    CustomHeadFooterView *view = [tableview dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([CustomHeadFooterView class])];

      if (view == nil) {
          view = [[CustomHeadFooterView alloc]initWithReuseIdentifier:NSStringFromClass([CustomHeadFooterView class])];
      }
      view.backgroundColor = [UIColor yellowColor];
      return view;
    
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    if(self = [super initWithReuseIdentifier:reuseIdentifier]){
        
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.icoIamgeView = [[UIImageView alloc]initWithFrame:CGRectMake(12, 8, 55, 55)];
        self.icoIamgeView.image = [UIImage imageNamed:@"ceshiyongdeyouxitupian"];
        self.icoIamgeView.layer.cornerRadius = 8;
        self.icoIamgeView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.icoIamgeView];
        
        
           self.nameNiChengLabel  = [[UILabel alloc]initWithFrame:CGRectMake( self.icoIamgeView.right+10, 10, 200, 14)];
            self.nameNiChengLabel.text = @"幻想骑士团";
            self.nameNiChengLabel.font = [UIFont systemFontOfSize:14];
        self.nameNiChengLabel.textColor = RGB(39, 42, 51);
          //  self.nameNiChengLabel.backgroundColor = [UIColor redColor];
            self.nameNiChengLabel.textAlignment =  NSTextAlignmentLeft;
        //    self.jianjienLabel.layer.borderWidth = 1;
        //    self.jianjienLabel.layer.borderColor = RGB(38, 154, 255).CGColor;
        //    self.jianjienLabel.layer.cornerRadius = 3;
        //    self.jianjienLabel.layer.masksToBounds = YES;
            [self.contentView addSubview:self.nameNiChengLabel];
        
        
        self.liaboshuliaLabel  = [[UILabel alloc]initWithFrame:CGRectMake( self.icoIamgeView.right+10, self.nameNiChengLabel.bottom+6, kScreenW-140, 11)];
        self.liaboshuliaLabel.text = @"该游戏礼包有三个";
        self.liaboshuliaLabel.font = [UIFont systemFontOfSize:11];
        self.liaboshuliaLabel.textColor = RGB(130, 130, 130);
            //  self.nameNiChengLabel.backgroundColor = [UIColor redColor];
        self.liaboshuliaLabel.textAlignment =  NSTextAlignmentLeft;
        [self.contentView addSubview:self.liaboshuliaLabel];
        
        
        
        self.libao1Label  = [[UILabel alloc]initWithFrame:CGRectMake( self.icoIamgeView.right+10, self.liaboshuliaLabel.bottom+6, 36, 12)];
        self.libao1Label.text = @"礼包";
        self.libao1Label.font = [UIFont systemFontOfSize:8];
        self.libao1Label.textColor = RGB(255, 255, 255);
                 //  self.nameNiChengLabel.backgroundColor = [UIColor redColor];
        self.libao1Label.textAlignment =  NSTextAlignmentCenter;
        self.libao1Label.backgroundColor = RGB(253, 178, 50);
        self.libao1Label.layer.cornerRadius = 3;
        self.libao1Label.layer.masksToBounds = YES;
       [self.contentView addSubview:self.libao1Label];
        
        self.libao2Label  = [[UILabel alloc]initWithFrame:CGRectMake( self.libao1Label.right+3, self.liaboshuliaLabel.bottom+6, 40, 12)];
          self.libao2Label.text = @"满V版";
          self.libao2Label.font = [UIFont systemFontOfSize:8];
          self.libao2Label.textColor = RGB(255, 255, 255);
                   //  self.nameNiChengLabel.backgroundColor = [UIColor redColor];
          self.libao2Label.textAlignment =  NSTextAlignmentCenter;
          self.libao2Label.backgroundColor = RGB(254, 83, 37);
          self.libao2Label.layer.cornerRadius = 3;
          self.libao2Label.layer.masksToBounds = YES;
         [self.contentView addSubview:self.libao2Label];
        
        
        self.libao3Label  = [[UILabel alloc]initWithFrame:CGRectMake( self.libao2Label.right+3, self.liaboshuliaLabel.bottom+6, 75, 12)];
              self.libao3Label.text = @"充值1:50 送vip";
              self.libao3Label.font = [UIFont systemFontOfSize:8];
              self.libao3Label.textColor = RGB(255, 255, 255);
                       //  self.nameNiChengLabel.backgroundColor = [UIColor redColor];
              self.libao3Label.textAlignment =  NSTextAlignmentCenter;
              self.libao3Label.backgroundColor = RGB(47, 179, 57);
              self.libao3Label.layer.cornerRadius = 3;
              self.libao3Label.layer.masksToBounds = YES;
             [self.contentView addSubview:self.libao3Label];
          
        
        
        UIButton *topUpbut = [UIButton buttonWithType:UIButtonTypeCustom];
        topUpbut.frame = CGRectMake(kScreenW-35-20, 15, 35,40);
       // [topUpbut setBackgroundImage:[UIImage imageNamed:@"g_lt_liabo"] forState:UIControlStateNormal];
        [topUpbut setImage:[UIImage imageNamed:@"g_lt_liabo"] forState:UIControlStateNormal];
        [topUpbut setImage:[UIImage imageNamed:@"g_lt_liabo"] forState:UIControlStateHighlighted];
        //        but.layer.cornerRadius = 65*CFLScaleValue/2;
          //        but.layer.masksToBounds = YES;
        [topUpbut addTarget:self action:@selector(btnGroupTitleClickd:) forControlEvents:UIControlEventTouchUpInside];
        self.zhangkaiBut = topUpbut;
        
        [self.contentView addSubview:topUpbut];
        
       
        
        
       
     }
     return self;
    
}

//当前控件的frame发生改变的时候会调用这个方法

- (void)layoutSubviews{
    [super layoutSubviews];
  
}



- (void)btnGroupTitleClickd:(UIButton *)sender{
   // NSLog(@"---%d",self.group.visible);
    //设置组状态
    self.group.visible = !self.group.isVisible;
    
    if(self.delegate&&[self.delegate respondsToSelector:@selector(groupHeaderViewDidClickTitleButton:)]){
        [self.delegate groupHeaderViewDidClickTitleButton:self];
    }
}

- (void)setGroup:(HWGroupModel *)group {
   //设置frame不要在这里设置frame，因为这个时候的当前控件(self)的宽和高都是0
   _group = group;
    
    [self.icoIamgeView sd_setImageWithURL:[NSURL URLWithString:group.icon] placeholderImage:nil];
    self.nameNiChengLabel.text = [NSString stringWithFormat:@"%@",group.name];
    self.libao1Label.hidden = YES;
    self.libao2Label.hidden = YES;
    self.libao3Label.hidden = YES;
    
    for (int i = 0; i < [group.biaoqian count]; i++) {
        if (i == 0) {
            self.libao1Label.hidden = NO;
             self.libao2Label.text = @"满V版";
             self.libao1Label.text = [NSString stringWithFormat:@"%@",group.biaoqian[i]];
            
        } else if (i == 2) {
             self.libao2Label.hidden = NO;
             self.libao2Label.text = @"满V版";
             self.libao2Label.text = [NSString stringWithFormat:@"%@",group.biaoqian[i]];
            
        }else if (i == 3) {
             self.libao3Label.hidden = NO;
            self.libao3Label.text = [NSString stringWithFormat:@"%@",group.biaoqian[i]];
            
        }
        
    
    }
    

    
    if (group.list.count > 0 ) {
        self.liaboshuliaLabel.text = [NSString stringWithFormat:@"该游戏礼包%1d个",group.list.count];
        
    } else {
        
        self.liaboshuliaLabel.text = [NSString stringWithFormat:@"该游戏%@礼包",@"无"];
        
    }
      
  
   if(self.group.isVisible){
       
       
      // self.btnGroupTitle.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);
       
//       [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_lt_liabo"] forState:UIControlStateNormal];
//       [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_lt_liabo"] forState:UIControlStateHighlighted];
       [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_l_liabo"] forState:UIControlStateNormal];
       [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_l_liabo"] forState:UIControlStateHighlighted];
       
   }else{
      
       [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_l_liabo"] forState:UIControlStateNormal];
       [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_l_liabo"] forState:UIControlStateHighlighted];
       
       [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_lt_liabo"] forState:UIControlStateNormal];
            [self.zhangkaiBut setImage:[UIImage imageNamed:@"g_lt_liabo"] forState:UIControlStateHighlighted];
       
   }
   
}






@end
